


set(protofiles "user.proto" "blog.proto" "home.proto")
set(cur_path ${CMAKE_CURRENT_BINARY_DIR})
set(src_path ${CMAKE_CURRENT_LIST_DIR})
set(proto_path ${CMAKE_SOURCE_DIR}/src/protos)
set(source_path ${CMAKE_SOURCE_DIR}/build/src)


set(src_list "")
foreach(file  ${protofiles})
# compile protobuf file 
    set(hfile "")
    set(sfile "")
    string(REPLACE ".proto" ".pb.h" hfile ${file}) # user.pb.h
    string(REPLACE ".proto" ".pb.cc" sfile ${file}) # user.pb.cc
    if(NOT EXISTS ${cur_path}/${sfile}) 
        add_custom_command(
            PRE_BUILD
            COMMAND protoc
            ARGS -I ${proto_path} --cpp_out=${cur_path} ${proto_path}/${file}
            DEPENDS ${proto_path}/${file}
            OUTPUT ${cur_path}/${sfile}
            COMMENT "proto compile: " ${file}
        )
    endif()
    list(APPEND src_list ${cur_path}/${sfile})
endforeach()


file(GLOB SRC_FILES ${CMAKE_CURRENT_LIST_DIR}/*.cpp)

add_executable(httpserver ${SRC_FILES} ${src_list})

target_include_directories(httpserver PUBLIC ${cur_path})
target_include_directories(httpserver PUBLIC ${source_path})

target_link_libraries(httpserver PUBLIC 
                    -lodb 
                    -lodb-mysql 
                    -lodb-boost 
                    brpc_etcd
                    )